/*     */ package com.zimbra.qa.unittest.prov.ldap;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Group;
/*     */ import com.zimbra.cs.account.accesscontrol.GranteeType;
/*     */ import com.zimbra.cs.account.accesscontrol.InlineAttrRight;
/*     */ import com.zimbra.cs.account.accesscontrol.Right;
/*     */ import com.zimbra.cs.account.accesscontrol.RightCommand;
/*     */ import com.zimbra.cs.account.accesscontrol.RightCommand.AllEffectiveRights;
/*     */ import com.zimbra.cs.account.accesscontrol.RightCommand.EffectiveAttr;
/*     */ import com.zimbra.cs.account.accesscontrol.RightCommand.EffectiveRights;
/*     */ import com.zimbra.cs.account.accesscontrol.RightCommand.RightAggregation;
/*     */ import com.zimbra.cs.account.accesscontrol.RightCommand.RightsByTargetType;
/*     */ import com.zimbra.cs.account.accesscontrol.RightManager;
/*     */ import com.zimbra.cs.account.accesscontrol.RightModifier;
/*     */ import com.zimbra.cs.account.accesscontrol.TargetType;
/*     */ import com.zimbra.cs.account.ldap.LdapProv;
/*     */ import com.zimbra.qa.QA.Bug;
/*     */ import com.zimbra.soap.admin.type.GranteeSelector.GranteeBy;
/*     */ import com.zimbra.soap.type.TargetBy;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ import java.util.SortedMap;
/*     */ import org.junit.AfterClass;
/*     */ import org.junit.Assert;
/*     */ import org.junit.BeforeClass;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestACLEffectiveRights
/*     */   extends LdapTest
/*     */ {
/*     */   private static Right ADMIN_PRESET_ACCOUNT;
/*     */   private static LdapProvTestUtil provUtil;
/*     */   private static LdapProv prov;
/*     */   private static Domain domain;
/*     */   private static String BASE_DOMAIN_NAME;
/*     */   private static Account globalAdmin;
/*     */   
/*     */   @BeforeClass
/*     */   public static void init()
/*     */     throws Exception
/*     */   {
/*  63 */     provUtil = new LdapProvTestUtil();
/*  64 */     prov = provUtil.getProv();
/*  65 */     domain = provUtil.createDomain(baseDomainName(), null);
/*  66 */     BASE_DOMAIN_NAME = domain.getName();
/*  67 */     globalAdmin = provUtil.createGlobalAdmin("globaladmin", domain);
/*     */     
/*  69 */     ADMIN_PRESET_ACCOUNT = getRight("test-preset-account");
/*     */   }
/*     */   
/*     */   @AfterClass
/*     */   public static void cleanup() throws Exception {
/*  74 */     Cleanup.deleteAll(new String[] { baseDomainName() });
/*     */   }
/*     */   
/*     */   private static Right getRight(String right) throws ServiceException {
/*  78 */     return RightManager.getInstance().getRight(right);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getEffectiveRights() throws Exception {
/*  83 */     Domain domain = provUtil.createDomain(genDomainSegmentName() + "." + BASE_DOMAIN_NAME);
/*  84 */     Account target = provUtil.createAccount(genAcctNameLocalPart("user"), domain);
/*  85 */     Account grantee = provUtil.createDelegatedAdmin(genAcctNameLocalPart("da"), domain);
/*  86 */     Account grantingAccount = globalAdmin;
/*     */     
/*  88 */     TargetType targetType = TargetType.getTargetType(target);
/*  89 */     GranteeType granteeType = GranteeType.GT_USER;
/*  90 */     Right right = ADMIN_PRESET_ACCOUNT;
/*     */     
/*  92 */     RightCommand.grantRight(prov, grantingAccount, targetType.getCode(), TargetBy.name, target.getName(), granteeType.getCode(), GranteeSelector.GranteeBy.name, grantee.getName(), null, right.getName(), null);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  98 */     RightCommand.EffectiveRights effRights = RightCommand.getEffectiveRights(prov, TargetType.account.getCode(), TargetBy.name, target.getName(), GranteeSelector.GranteeBy.name, grantee.getName(), false, false);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 104 */     Assert.assertTrue(effRights.presetRights().contains(right.getName()));
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getAllEffectiveRights()
/*     */     throws Exception
/*     */   {
/* 111 */     Domain domain = provUtil.createDomain(genDomainSegmentName() + "." + BASE_DOMAIN_NAME);
/* 112 */     Account target = provUtil.createAccount(genAcctNameLocalPart("user"), domain);
/* 113 */     Account grantee = provUtil.createDelegatedAdmin(genAcctNameLocalPart("da"), domain);
/* 114 */     Account grantingAccount = globalAdmin;
/*     */     
/* 116 */     TargetType targetType = TargetType.getTargetType(target);
/* 117 */     GranteeType granteeType = GranteeType.GT_USER;
/* 118 */     Right right = ADMIN_PRESET_ACCOUNT;
/*     */     
/* 120 */     RightCommand.grantRight(prov, grantingAccount, targetType.getCode(), TargetBy.name, target.getName(), granteeType.getCode(), GranteeSelector.GranteeBy.name, grantee.getName(), null, right.getName(), null);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 126 */     RightCommand.AllEffectiveRights allEffRights = RightCommand.getAllEffectiveRights(prov, granteeType.getCode(), GranteeSelector.GranteeBy.name, grantee.getName(), false, false);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 131 */     Map<TargetType, RightCommand.RightsByTargetType> rbttMap = allEffRights.rightsByTargetType();
/* 132 */     RightCommand.RightsByTargetType rbtt = (RightCommand.RightsByTargetType)rbttMap.get(targetType);
/*     */     
/* 134 */     boolean found = false;
/* 135 */     for (RightCommand.RightAggregation rightsByEntries : rbtt.entries()) {
/* 136 */       Set<String> targetNames = rightsByEntries.entries();
/*     */       
/* 138 */       if (targetNames.contains(target.getName()))
/*     */       {
/*     */ 
/* 141 */         RightCommand.EffectiveRights effRights = rightsByEntries.effectiveRights();
/* 142 */         List<String> presetRights = effRights.presetRights();
/* 143 */         if (presetRights.contains(right.getName())) {
/* 144 */           found = true;
/*     */         }
/*     */       }
/*     */     }
/* 148 */     Assert.assertTrue(found);
/*     */   }
/*     */   
/*     */   @QA.Bug(bug={70206})
/*     */   @Test
/*     */   public void bug70206() throws Exception {
/* 154 */     Account acct = provUtil.createDelegatedAdmin(genAcctNameLocalPart(), domain);
/* 155 */     Group group = provUtil.createGroup(genGroupNameLocalPart(), domain, false);
/*     */     
/* 157 */     Account grantingAccount = globalAdmin;
/*     */     
/* 159 */     String presetRightUnderTest = "deleteDistributionList";
/*     */     
/* 161 */     String attrUnderTest = "zimbraHideInGal";
/* 162 */     String attrRightUnderTest = InlineAttrRight.composeSetRight(TargetType.dl, attrUnderTest);
/*     */     
/*     */ 
/*     */ 
/* 166 */     RightCommand.grantRight(prov, grantingAccount, TargetType.global.getCode(), null, null, GranteeType.GT_USER.getCode(), GranteeSelector.GranteeBy.name, acct.getName(), null, "adminConsoleDLRights", null);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 173 */     RightCommand.grantRight(prov, grantingAccount, TargetType.global.getCode(), null, null, GranteeType.GT_USER.getCode(), GranteeSelector.GranteeBy.name, acct.getName(), null, presetRightUnderTest, RightModifier.RM_DENY);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 180 */     RightCommand.grantRight(prov, grantingAccount, TargetType.dl.getCode(), TargetBy.name, group.getName(), GranteeType.GT_USER.getCode(), GranteeSelector.GranteeBy.name, acct.getName(), null, attrRightUnderTest, null);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 187 */     RightCommand.grantRight(prov, grantingAccount, TargetType.global.getCode(), null, null, GranteeType.GT_USER.getCode(), GranteeSelector.GranteeBy.name, acct.getName(), null, attrRightUnderTest, RightModifier.RM_DENY);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 194 */     RightCommand.grantRight(prov, grantingAccount, TargetType.dl.getCode(), TargetBy.name, group.getName(), GranteeType.GT_USER.getCode(), GranteeSelector.GranteeBy.name, acct.getName(), null, presetRightUnderTest, null);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 200 */     RightCommand.EffectiveRights effRights = RightCommand.getEffectiveRights(prov, TargetType.dl.getCode(), TargetBy.name, group.getName(), GranteeSelector.GranteeBy.name, acct.getName(), false, false);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 206 */     List<String> presetRights = effRights.presetRights();
/* 207 */     SortedMap<String, RightCommand.EffectiveAttr> setAttrRights = effRights.canSetAttrs();
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 214 */     Assert.assertTrue(presetRights.contains("deleteDistributionList"));
/* 215 */     Assert.assertTrue(setAttrRights.containsKey(attrUnderTest));
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/ldap/TestACLEffectiveRights.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */